package com.shambles.manage2.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shambles.manage2.service.SubscribeService;
import com.shambles.manage2.tkmapper.entity.MessageRequestVM;
import com.shambles.manage2.tkmapper.entity.SubscribeInformation;
import com.shambles.manage2.tkmapper.mapper.SubscribeDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yangsy
 * @description
 * @date 2020/03/08
 */
@Service
public class SubscribeServiceImpl implements SubscribeService {

    @Autowired
    private SubscribeDetailMapper subscribeDetailMapper;

    /**
     * 查询预约明细类型和数量
     */
    @Override
    public SubscribeInformation querySubscribeInfo(String id){
        SubscribeInformation subList=this.subscribeDetailMapper.querySubscribeInfo(id);
        subList.SubDetail=this.subscribeDetailMapper.querySubscribeDetail(subList.getGuid());
        subList.UrlList=this.subscribeDetailMapper.queryImageUrl(subList.getGuid());
        return subList;
    }

    /**
     * 个人预约信息记录
     */
    @Override
     public PageInfo<SubscribeInformation> queryPersonalInfo(MessageRequestVM messageRequestVM, String openId){
         PageInfo<SubscribeInformation> subscribeInformation = PageHelper.startPage(messageRequestVM.getPageIndex(), messageRequestVM.getPageSize()).doSelectPageInfo(() ->
                  this.subscribeDetailMapper.queryPersonalInfo(openId)
             );
         List<SubscribeInformation> subList = subscribeInformation.getList();
        for(SubscribeInformation item:subList){
            item.SubDetail=this.subscribeDetailMapper.querySubscribeDetail(item.getGuid());
            item.UrlList=this.subscribeDetailMapper.queryImageUrl(item.getGuid());
        }
        return subscribeInformation;
    }

}
